<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>确认订单-波罗鸡</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script src="{{url('js/jquery.min.js')}}"></script>
    <script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <link href="{{url('css/order/style.css')}}" rel="stylesheet" type="text/css"/>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/weui/1.1.1/style/weui.min.css">
    <link rel="stylesheet" href="//cdn.bootcss.com/jquery-weui/1.1.1/css/jquery-weui.min.css">
    <script src="//cdn.bootcss.com/jquery-weui/1.1.1/js/jquery-weui.min.js"></script>
</head>
<body style="background:#f7f7f7">
<section class="aui-flexView">
    <header class="aui-navBar aui-navBar-fixed">
        <a href="javascript:;" class="aui-navBar-item" onclick="javascript:history.back(-1);">
            <i class="icon icon-return"></i>
        </a>
        <div class="aui-center">
            <span class="aui-center-title">确认订单</span>
        </div>
        <a href="javascript:;" class="aui-navBar-item">
            <i class="icon icon-sys"></i>
        </a>
    </header>
    <section class="aui-scrollView">
        <div class="aui-order-box">
            <div class="aui-flex aui-choice-white aui-mar15">
                <div class="aui-flex-box">
                    <span id="select_tip">请选择收货地址</span>
                    <span id="realname_show"></span>&nbsp;
                    <span id="phone_show"></span>&nbsp;
                    <span id="address_show"></span>
                </div>
                <input id="phone" type="hidden" value="" />
                <input id="address" type="hidden" value="" />
                <input id="realname" type="hidden" value="" />

                <div class="aui-flex-triangle" style="color:#fff">.</div>
            </div>
            <div class="aui-flex aui-choice-white">
                <div class="aui-flex-box">
                    <h1>商品清单1件</h1>
                </div>
            </div>
            <div class="aui-flex aui-flex-default aui-mar15">
                <div class="aui-flex-goods">
                    <img src="{{route('Api.Image.Show',['id'=>$good->thumb_id])}}" alt="">
                </div>
                <div class="aui-flex-box">
                    <h2>@if($good){{$good->name}}@endif</h2>
                    <input id="gid" type="hidden" value="@if($good){{$good->id}}@endif">
                    <input id="num" type="hidden" value="{{$num}}">
                    {{--<p>尺码：43</p>--}}
                    <div class="aui-flex aui-flex-clear">
                        <div class="aui-flex-box">￥@if($good){{$good->amount}}@endif</div>
                        <div>x{{$num}}</div>
                    </div>
                </div>
            </div>
            <div class="aui-flex aui-choice-white b-line">
                <div class="aui-flex-box">配送方式</div>
                <div class="aui-flex-triangle">普通快递</div>
            </div>
            <div class="aui-flex aui-choice-white b-line">
                <div class="aui-flex-box">快递费用</div>
                <div class="aui-flex-triangle">￥{{$e_amount}}</div>
            </div>
            {{--<div class="aui-flex aui-choice-white b-line">--}}
                {{--<div class="aui-flex-box">优惠券</div>--}}
                {{--<div class="aui-flex-triangle">无可用</div>--}}
            {{--</div>--}}
            {{--<div class="aui-flex aui-choice-white  aui-mar15">--}}
                {{--<div class="aui-flex-box">发票信息</div>--}}
                {{--<div class="aui-flex-triangle">不可开发票</div>--}}
            {{--</div>--}}
            <div class="aui-flex aui-choice-white ">
                <div class="aui-flex-box">
                    <h2>商品总价</h2>
                    {{--<h3>运费总额</h3>--}}
                    {{--<p>年度消费满2000元,订单满99元包邮。您已消费38900元</p>--}}
                </div>
                <div class="aui-flex-triangle aui-flex-triangle-clear">
                    <h4>￥{{$amount}}</h4>
                    {{--<p>+￥10元</p>--}}
                </div>
            </div>
        </div>
    </section>
    <footer class="aui-bar-footer">
        <div class="aui-flex">
            <div class="aui-flex-box">
                应付金额：<em>￥{{$amount}}</em>
            </div>
            <div class="aui-btn-button">
                <button>去支付</button>
            </div>
        </div>
    </footer>
</section>
<script>
    $(function () {

        wxIni();
        function wxIni(){
            var url=location.href;
            $.ajax({
                type : "post",
                url : "{{route('Api.Wechat.getJsApiPacket')}}",//替换网址，xxx根据自己jssdk文件位置修改
                dataType : "json",
                data:{url:url},
                success : function(obj){
                    if(obj.level == 'success'){
                        var data = obj.data;
                        wx.config({
                            appId: data.appId,
                            timestamp: data.timestamp,
                            nonceStr: data.nonceStr,
                            signature: data.signature,
                            jsApiList: [
                                "updateAppMessageShareData", //分享给好友
                                "updateTimelineShareData", //分享到朋友圈
                                "chooseWXPay","openAddress"
                            ]
                        });
                    }
                },
                error:function(data){
                    console.log("连接失败！");
                }
            });
        }

        $('.aui-flex-box').click(function () {
            {{--var gid = $("#gid").val();--}}
            {{--var num = $("#num").val();--}}

            {{--$.cookie('gid', gid, { expires: 7 });--}}
            {{--$.cookie('num', num, { expires: 7 });--}}
            {{--window.location.href="{{route('Home.User.myNewAddress')}}?type=new_order";--}}
            wx.openAddress({
                success: function (res) {
                    var userName = res.userName; // 收货人姓名
                    var provinceName = res.provinceName; // 国标收货地址第一级地址（省）
                    var cityName = res.cityName; // 国标收货地址第二级地址（市）
                    var detailInfo = res.detailInfo; // 详细收货地址信息
                    var telNumber = res.telNumber; // 收货人手机号码
                    $('#phone').val(telNumber);
                    $('#phone_show').html(telNumber);
                    $('#address').val(provinceName+cityName+detailInfo);
                    $('#address_show').html(provinceName+cityName+detailInfo);
                    $('#realname').val(userName);
                    $('#realname_show').html(userName);
                    $('#select_tip').hide();
                }
            });
        });

        $('.aui-btn-button').click(function () {
            var realname = $('#realname').val();
            var phone    = $('#phone').val();
            var address  = $('#address').val();
            var num = $("#num").val();
            var gid = $("#gid").val();
            $.ajax({
                type : "post",
                url : "{{route('Api.Good.buildOrder')}}",
                dataType : "json",
                data:{
                    gid:gid,
                    num:num,
                    realname:realname,
                    phone:phone,
                    address:address
                },
                success : function(obj){
                    if(obj.level == 'success'){
                        startJsApiPay(obj.data.order_num);
                    }else {
                        $.toast(obj.message,"forbidden");
                    }
                },
                error:function(obj){
                    console.log(obj);
                }
            });
        });

        function startJsApiPay(order_num) {
            $.ajax({
                type:"post",
                url:'{{route('Api.Payment.payByWechatJsApi')}}',
                dataType:"json",
                data:{
                    order_num:order_num
                },
                success:function(obj){
                    if(obj.level == "success"){
                        $.hideLoading();
                        WXPayment(obj.data);
                    }else {
                        $.toast(obj.message, "forbidden");
                    }
                },
                error:function(obj){
                    console.log(obj);
                }
            });
        }

        function WXPayment(configJSON) {
            wx.chooseWXPay({
                timestamp: configJSON.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                nonceStr: configJSON.nonceStr, // 支付签名随机串，不长于 32 位
                package: configJSON.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
                signType: configJSON.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                paySign: configJSON.paySign, // 支付签名
                success: function (res) {
                    window.location.href="{{route('Home.User.myexchange')}}?type=dfh";
                }
            });

            {{--if (typeof WeixinJSBridge === 'undefined') {--}}
                {{--$.toast('请在微信在打开页面', "forbidden");--}}
                {{--return false;--}}
            {{--}--}}
            {{--WeixinJSBridge.invoke('getBrandWCPayRequest', configJSON, function (res) {--}}
                {{--switch (res.err_msg) {--}}
                    {{--case 'get_brand_wcpay_request:cancel':--}}
                        {{--alert('用户取消支付！');--}}
                        {{--break;--}}
                    {{--case 'get_brand_wcpay_request:fail':--}}
                        {{--alert('支付失败！（' + res.err_desc + '）');--}}
                        {{--break;--}}
                    {{--case 'get_brand_wcpay_request:ok':--}}
                        {{--$.toast('支付成功',function () {--}}
                            {{--window.location.href="{{route('Home.User.myexchange')}}?type=dfh";--}}
                        {{--});--}}
                        {{--break;--}}
                    {{--default:--}}
                        {{--alert(JSON.stringify(res));--}}
                        {{--break;--}}
                {{--}--}}
            {{--});--}}
        }
    })
</script>
</body>
</html>
